/**
 * 
 */
package com.dsbridge.enrollment.web;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.dsbridge.enrollment.business.CourseBusinessService;
import com.dsbridge.enrollment.entities.Subject;

/**
 * @author rithvik
 * 
 */
@ManagedBean
@RequestScoped
public class SubjectController {

	private String subjectName;

	public String getSubjectName() {
		return subjectName;
	}

	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}

	// Some Action needs to be Done.
	public String createSubject() {

		ApplicationContext appContext = FacesContextUtils
				.getRequiredWebApplicationContext(FacesContext
						.getCurrentInstance());
		CourseBusinessService courseBusinessService = appContext
				.getBean(CourseBusinessService.class);
		Subject subject=new Subject();
		subject.setSubjectName(subjectName);
		int i = courseBusinessService.createSubject(subject);
		if (i > 0) {
			FacesContext.getCurrentInstance().addMessage(
					"SubjectCreateMessage",
					new FacesMessage(FacesMessage.SEVERITY_INFO,
							"Subject Created Succesfully", "D"));
			return "subjectResponse";
		} else {
			return "studentError";
		}
	}

}
